package com.vogue.supplymall.shop.domain.mapper;

import com.vogue.ssm.database.util.SqlLangDriver;
import com.vogue.supplymall.common.domain.dto.SearchInfo;
import com.vogue.supplymall.shop.domain.model.Product;
import com.vogue.supplymall.shop.domain.provider.ProductSqlProvider;
import com.vogue.supplymall.shop.domain.provider.ProductUnitSqlProvider;

import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;

/**
 * The interface Product mapper.
 *
 * @Aouthor: zhangliang
 * @Date: Create in 2017-12-05
 */
@Mapper
public interface ProductMapper extends BaseMapper<Product, Long> {

    /**
     * Find by id shop.
     * 根据id检索商品
     *
     * @param id the id
     * @return the shop
     */
    @Select("SELECT p.id, p.syscodeid, p.shopid, p.pid, p.`name`, p.`code`, p.detailinfo, p.itemlabel, p.mainlyflag, p.matchid, p.disabledflag, p.hiddenflag, p.sendlvl, p.createdate, p.modifydate FROM product p WHERE p.id = #{id}")
    @Lang(SqlLangDriver.class)
    Product findById(Long id);

    /**
     * Find product list.
     * 根据条件检索商品
     *
     * @param searchInfo the search info
     * @return the list
     * @throws RuntimeException the runtime exception
     */
    @SelectProvider(type = ProductSqlProvider.class, method = "find")
    List<Map<String, Object>> findProduct(SearchInfo searchInfo) throws RuntimeException;

    /**
     * Find product list.
     * 根据条件检索商品详情的单位
     *
     * @param searchInfo the search info
     * @return the list
     * @throws RuntimeException the runtime exception
     */
    @SelectProvider(type = ProductUnitSqlProvider.class, method = "find")
    List<Map<String, Object>> findProductUnit(SearchInfo searchInfo) throws RuntimeException;
    /**
     * 根据sysCodeId,shopId和matchId找到对应的商品
     * @return
     */
    @Select("select * from product s where syscodeid=#{arg0} and shopId=#{arg1} and matchId in (#{arg2})")
    @Lang(SqlLangDriver.class)
    public List<Product> findProductBySSM(Long sysCodeId, Long shopId,List<String> matchIds);
    /**
     * 根据sysCodeId,shopId找到对应的商品
     * @return
     */
    @Select("select * from product s where syscodeid=#{arg0} and shopId=#{arg1}")
    @Lang(SqlLangDriver.class)
    public List<Product> findProductBySS(Long sysCodeId, Long shopId);

    /**
     * 查找满足条件的总店铺的数量
     *
     * @param searchInfo
     * @return
     * @throws RuntimeException
     */
    @SelectProvider(type = ProductSqlProvider.class, method = "findCount")
    Long findProductCountBySql(SearchInfo searchInfo) throws RuntimeException;
}
